//
//  YbrDevice.m
//  wifibox
//
//  Created by os X 10.9 on 15-1-12.
//  Copyright (c) 2015年 yinbaner. All rights reserved.
//

#import "YbrDevice.h"
#import "YbrSetUpBaseReq.h"
#import "AFNPhalApiClient.h"
#import "YbrJsonUtil.h"
#import "IWHttpTool.h"


@implementation YbrDevice

// 添加一个方法，可以自己访问自己的属性，然后记录下来，
//-(void)getDeviceInfo
//{
//    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//        NSDictionary *params2           =   [NSDictionary dictionaryWithObjectsAndKeys:
//                                             @"TransportState AudioSource AudioDSP AudioEQ RepeatMode PlayMode AudioMute CurrentVolume",@"Variables", nil];
//        YbrSetUpBaseReq *setupBaseReq   =   [YbrSetUpBaseReq InitBaseReq:@"GetPlayerState" body:params2];
//        NSMutableDictionary *params     =   [NSMutableDictionary dictionary];
//        params[@"CMD"]                  =   @"HTTPAPI";
//        NSString *req                   =   [YbrJsonUtil getJson:setupBaseReq];
//        params[@"JSONREQ"]              =   req;
//        
//        // http请求
//        [IWHttpTool postWithURL:[NSString stringWithFormat:@"http://%@/httpapi.html",self.DeviceIpAddr] params:params success:^(id json) {
//            if (json == nil || [json[@"Result"] intValue] != 0) {
//                return;
//            }
//            
//            NSDictionary * dict = json[@"Body"];
//            self.AudioDSP       = dict[@"AudioDSP"];
//            self.AudioEQ        = dict[@"AudioEQ"];
//            self.AudioMute      = dict[@"AudioMute"];
//            self.AudioSource    = dict[@"AudioSource"];
//            self.PlayMode       = dict[@"PlayMode"];
//            self.RepeatMode     = dict[@"RepeatMode"];
//            self.TransportState = dict[@"TransportState"];
//            self.currentVolume  = [dict[@"CurrentVolume"] intValue];
//            
//            if([self.TransportState isEqualToString:@"PLAYING"])
//            {
//                
//            }
//            
//            if (!self.AudioMute)
//            {
//                self.AudioEQ = @"0";
//            }
//            if (!self.PlayMode)
//            {
//                self.PlayMode = @"0";
//            }
            
//            [self toString];
            
            // 发送广播
//            [self postDlnaDeviceChange];
//        } failure:^(NSError *error) {
            // add code here
//        }];
//    
//        NSString * version  =  @"";
//        
//        if (self.DeviceFiremwareVersion != nil && self.DeviceFiremwareVersion.length > 2)
//        {
//            version         = [[self.DeviceFiremwareVersion substringWithRange:NSMakeRange(0, 2)] lowercaseString];
//        }
//        // 请求固件
//        NSMutableDictionary *params3    = [NSMutableDictionary dictionary];
//        [params3 setObject:version forKey:@"version"];
//        PhalApiClient * client          = [[AFNPhalApiClient sharedClient] withService:API_CheckHardWareVersion];
//        [client setParams:params3];
//        [client request:^(id resultObject) {
//            if (200 != [resultObject[@"ret"] intValue])
//            {
//                return;
//            }
//            NSDictionary * data = resultObject[@"data"];
        
//            if ([data[@"code"] intValue] == 13) {
//                return;
//            }
        
//            NSLog(@"-----请求固件-----11111--------new: %@------old: %@",data[@"code"],version);
//            if (![data[@"version"] isEqualToString:version]) {
//                return;
//            }
//            
//            NSString * newHardWareVersion = data[@"name"];
//            
//            NSLog(@"-----请求固件-----22222--------new: %@------old: %@------isSame: %d",newHardWareVersion,self.DeviceFiremwareVersion,[newHardWareVersion isEqualToString:self.DeviceFiremwareVersion]);
//            
//            if (![newHardWareVersion isEqualToString:self.DeviceFiremwareVersion])
//            {
//                self.isNeedUpgrade = 1;
//                [self postDlnaDeviceChange];// 通知界面更新固件
//            }
//        } failureBlock:^(id error) {
//            // add code here
//        }];
//    });
//}


-(void)toString
{
    NSLog(@"-----查看当前设备的属性--------AudioDSP: %@, AudioEQ: %@, AudioMute: %@, AudioSource: %@, PlayMode: %@, RepeatMode: %@, TransportState: %@, currentvolume:%d",self.AudioDSP,self.AudioEQ,self.AudioMute,self.AudioSource,self.PlayMode,self.RepeatMode,self.TransportState,self.currentVolume);
}


-(void)postDlnaDeviceChange
{
//    [[NSNotificationCenter defaultCenter] postNotificationName:DLNADeviceChange object:nil];
}
@end







